<?php


namespace app\api\library\order\orderRefund;


use app\api\model\MallCollage;
use app\api\model\MallOrder;
use think\facade\Db;

class V
{
    public static function run($param)
    {
        $userId  = _checkEmptyParam($param[ 'userId' ], '用户ID不能为空');
        $orderId = _checkEmptyParam($param[ 'orderId' ], '订单ID不能为空');
        $order   = Db::name('mall_order')->where([['id', '=', $orderId]])->find();
//        if (empty($order)) {
//            _outPut(204, [], '订单不存在');
//        }
        if ( !empty($order[ 'receipt_time' ]) && $order[ 'receipt_time' ] - 15 * 3600 * 24 > time()){
            _outPut(204,[],'订单已收货超过15天，不能退款');
        }
            if (false === MallOrder::where('id', $orderId)->update(['refund_status' => 10, 'order_status' => 70, 'submit_refund_time' => time()])) {
                _outPut(204, [], '订单退款失败');
            }
        $collageId = MallOrder::where('id', $orderId)->value('collage_id');
        if (false === MallCollage::where('collage_id', $collageId)->update(['status' => 0])) {
            _outPut(204, [], '订单退款失败');
        }
        _outPut(200, [], '申请退款成功');
    }
}